< previous page page_301 next page >

Page 301
have 32 bits. Each of these bits can have a 1 or 0 value (which, in a sense, corresponds to True or False).
For example:
If you apply the NOT operator to a 16-bit variable containing the number 5, you get
5 = 0000000000000101 (binary)
Not 5 -> Not 0000000000000101 (binary) -> 1111111111111010 (binary) -> &HFFFA
(hex) -> -6 (decimal)
As you see, the NOT operation is applied to each bit.
What happens when you use an operator that acts on two variables? The operation is applied to each pair of bits on the two variables. For example:
5 Or 2 ->
0000000000000101 (binary) Or 0000000000000010 (binary) ->
0000000000000111 (binary) -> 7
5 Or 2 = 7
You can use the Boolean.vbp project (in the Tutorials section on the CD-ROM) to experiment with different numbers and Boolean operators. Just uncheck the "Use Boolean Variables" checkbox to experiment with numbers. I encourage you to enter hex values in the two text boxes for your experiments (just precede the value with &H). The results will be displayed in hexadecimal, and you should grow accustomed to using only hexadecimal when dealing with Boolean operations.
Why is this important?
Because there are many situations where API functions and structures deal with individual bits and groups of bits within a numeric variable.
Combining Bits Using the OR Operator
Let's say you want to use the SetWindowPos function to change the position of a window on the screen. This function has a number of capabilities beyond those provided by the simple Move function included in Visual Basic. For example, you can set a window to be a "topmost" window, meaning that it will appear above other windows, even when it is not active. The exact operation of the function is defined by a "flag" parameter that is partially described in the Win32 documentation as follows:
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
uFlags
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
Specifies the window sizing and positioning flags. This parameter can be a combination of the following values:

 
< previous page page_301 next page >